package cn.com.headfree.file.dao.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.gta.edu.sdk.base.dao.impl.BaseDaoImpl;
import com.gta.edu.sdk.util.StringUtil;

import cn.com.headfree.file.dao.IFileDao;
import cn.com.headfree.file.entity.TCommonFile;
import org.mybatis.spring.support.SqlSessionDaoSupport;

@Repository("fileDao")
public class FileDaoImpl extends BaseDaoImpl<TCommonFile> implements IFileDao{

	@Override
	public List<TCommonFile> findFile(String sysCode, String businessId, String businessNode) {
		List<String> params = new ArrayList<String>();
//		Object[] params = new Object[3];
		StringBuilder sql = new StringBuilder("select * from T_COMMON_FILE where sys_code=? and business_id=? ");
		params.add(sysCode);
		params.add(businessId);
		if (!StringUtil.isNullOrEmpty(businessNode)) {
			sql.append(" and business_node=?");
			params.add(businessNode);
		}
		sql.append(" order by upload_time asc");
		return this.findAllBySQL(TCommonFile.class, sql.toString(), null, false, params.toArray());
	}

	public void delete(String id) {
		Map<String, Object> params = new HashMap<String, Object>();
		String sql = "delete from T_COMMON_FILE where id=#{id}";
		params.put("id", id);
		this.executeSql(sql, params);
	}

}
